#include<cstdio>
#include<algorithm>
using namespace std;
int x,y;
struct node
{
	int x,times;
};
node q[3000010];
int visit[1000010];
int heads=1,last=1;
int main()
{
	scanf("%d%d",&x,&y);
	if(y<x)
	{
		printf("%d",x-y);
		return 0;
	}
	node a;
	a.x=x;a.times=0;
	q[heads]=a;
	while(heads<=last)
	{
		node n=q[heads];
		heads++;
		if(n.x==y)
		{
			printf("%d",n.times);
			break;
		}
		node n1=n;
		n1.times++;
		n1.x+=1;
		if(!visit[n1.x])q[++last]=n1 , visit[n1.x]=1;
		n1.x-=2;
		if(!visit[n1.x])q[++last]=n1 , visit[n1.x]=1;
		n1.x+=1;
		n1.x*=2;
		if(n1.x<=100000&&!visit[n1.x])q[++last]=n1 , visit[n1.x]=1;
	}
	return 0;
}
